How can I prevent child window changing parent window behavior? - javascript

I have a page with a link with opening attribute '_blank'. But when click the link and open a new window, there are scripts in the new window, like 'window.opener.location' which changes the parent window's behaviors. However, this is not I wanted. How can I prevent this happening.
Thanks.

Related

Javascript Target Window Losing Name

I am opening a link in a new window w/ a tampermonkey script when a certain page loads:
window.open("http://www.google.com/search?q="+searchText+"", "myWindow",false);
This opens a child window with the correct google results. Then when I reload the parent window, the same script runs. It should display the new results in the 'myWindow' child window, but it doesn't work.
Right now, it spawns a completely new child window on each parent window reload. The name of the new child window is no longer 'myWindow' after google returns the results. How can I fix this?

changing link's onclick event and text from child window

I have a link on my parent page. When i click on it a popup opens. On the popup I have a button, when I click on it I need to change link's which is on the parent window(clicked to open popup), text and onClick event.
How can i do it?
Its better to reference a function on the parent window, rather than write code on the popup, so I'd use parent.some_function();
This way, if the original page changes, you can change the function there too, without searching through your popup windows.
You can not access tab/window elements from different tab/window.

How do I open new links outside of an iframe?

Is there any way to make an iframe act as if it were part of the page. Such as when I click a link, it either will open the links in a new tab/window by default, or have it so that when a link is clicked, it will open in the same window, but not just the iframe?
You can just set the target attribute. To open in the current top window (top frame):
Link Text
Or to open in a new window:
Link Text
There's also _parent for the parent window (not necessarily the top) and _self for the current window (the default).
Do you have control of the content that is in the iframe?
You could use target=_top for the links.

How can I open a new tab or window when a link is clicked?

I have same ancors/hyperlink in my html file. These point to a new website outside my site.
So I want that when the user clicks the link it should open a new tab or window. My website page should not be closed.
How can it be done?
open in tabs: there is nothing programatically that you can do to accomplish that, the only thing I'm thinking of is set the browser to open new links in tabs instead of new window...
to open in a new window all you need is to place a target in your anchors
click here
and, by the way there are more options to the target
target="_blank"
opens in a new Blank window
target="_parent"
opens in a Parent window (used when dealing with iframes and you want to open the link in other frame)
target="_self"
opens in it's own/self window (used when dealing with iframes and you want to open the link in the current frame)
target="_top"
opens in the top of all frames (it will open on top of all frames in the page, like a no-frame page will be display)
Click me to open in a new tab/window
Load the linked document into a new
blank window. This window is not
named.
If there is no existing window or
frame with the same name as specified
in the target, a new window is opened
with a name equal to the value of the
target.
Its the setting in a browser that determines whether to open the page in a new tab or in a new window.
Just add target="_blank" to the <a> tag
Click here
The easiest way is to use the target attribute in your anchors and set it to _blank:
Worse Than Failure
This is a dupe of opening links in the same window or in a new (tab) and https://stackoverflow.com/questions/118567/is-there-ever-a-good-reason-to-force-opening-a-new-browser-window. Basically - no. And there shouldn't be a way - you shouldn't impose your surfing preferences on unsuspecting others.

Pop-Up window on parent window from iFrame button

If I have a button within a iframe, how can I create a pop-up window that will appear as part of the parent window and not within the iframe window, when I press on this button, within the iframe?
Not sure that you can, this is a protection from iframes taking over a parent page. Meaning you couldn't have a floating div. You could popup a new window from the browser like normal.

Categories

Resources