javascript - What's the difference between window.open(url) and window.location.href = url on Firefox? -
I'm trying to create a bookmark, I want to present the current URL as a parameter to another URL.
Although I have found out that it is
javascript: (function () (window.open ("http: //www.somesi.te/some/thing ? Url = "+ encodeurIComponent (window .location.href))}) ()
does not work, while it
javascript: (function () {Window.location.href = "http: //www.somesi.te/some/thing? url =" + encodeurIComponent (window.location.href)}) ()
Apart from the apparent difference, that opens a new window, and window.location.href
changes the location, why does the latter work, while the former Just open another window in Is the original location?
It's fun on Firefox, working on Chrome works fine.
Is this a safety object?
The difference between window.open ()
and window.location.href
Is that there is a property of open ()
a method window class> and window.location
window category .
1. window.open ()
is the method on the window class
Calling the window. Open ()
method actually creates a window object, which can be organized in variables and manipulation according to your program requirements.
var mywindow = window.open ("http: // google") actually displays a window object to display that window, consider the following code: Com "); Mywindow.name =" Awesome Window "; console.log (typeW (MyWindow)); // - & gt;" Object "console.log (mywindow.name); // - & gt;" Awesome Window "
The reason for this is that your code is opening an unwanted window, this is because you were calling window.open ()
, whose The only purpose is life. Open a new window
2
However window.location
Is a readable property, window.location
has an built-in shortcut feature which allows to allocate window.location
, which has the same code as calling> Window.location.assign () , which does not return a window object, but to assign a new URL, using the root window object, the newly-appointed u The rl could be loaded in the browser window where the javascript was called to specify the location.
If you are creating a bookmark script, using the window.location
to grab the current window's URL and assign it to your program's URL string. The way.
You are getting unexpected behavior in different browsers, because of this there is no official public standard set for window objects, so how can each browser implement it? .
Comments
Post a Comment