please tell me how to open a page on click of hyper link in new browser instance (so that it should not be blocked by popup blocker) in flash AS3/ javascript
Thanks
You can open on a new tab (not on a new browser!) by doing this:
var urlRequest:URLRequest = new URLRequest("http://stackoverflow.com");
navigateToURL(urlRequest, "_blank");
Please, use it wisely...
JavaScript
// spawnWindow( 'www.duh.com', 'windowRef' )
function spawnWindow(URL, Name) {
var features = 'toolbar=0,location=0,status=0,menubar=0,scrollbars=0,resizable=0,width=900,height=700';
window.open(URL, Name, features);
}
AS3 code to call JS function
var retVal:int = ExternalInterface.call("spawnWindow",address,newId);
It is impossible! Unless you use ActiveX.
Related
Lets say you have code like this.
function openNewTab(url) {
const newTab = window.open(url, 'windowNameHehe');
};
Now every time you call this function it will open a new tab. However, if the window is already opened it will go to it and refresh/reload it. How do I stop it from reloading/refreshing and just bringing it to view?
Doing something like newTab.focus() or adding the boolean (true/false) in the 4th parameter of window.open isn't working for me either. Any help?
function openNewTab(url) {
var newTab = window.open(url, 'windowNameHehe', , false);
newTab.focus();
}
https://www.w3schools.com/jsref/met_win_open.asp
Open a URL in a new tab (and not a new window) using JavaScript
function openNewTab(url) {
const newTab = window.open('', 'windowNameHehe');
newTab.focus();
if (!newTab.location.hostname) {
newTab.location.href = url;
}
};
I am using Angular and tried to create a function to open url in current window. Below code in the controller actually opens new window instead:
$scope.openUrl = function(url) {
$window.open(url);
};
..when I use this ng-click='openUrl("someurl")'
So how to open in current window? I tried ng-click='parent.open()' and it doesn't work.
You could achieve this by using same old vainilla javascript:
$scope.openUrl = function(url) {
window.location = url;
};
$window is a wrapper for the browser's native window object. You can use this low-level method to actually change the location:
$window.location.href = url;
$location is a bit different. It can only extract from and manipulate the browser URL string. Its purpose isn't to actually navigate.
What does it not do? It does not cause a full page reload when the
browser URL is changed. To reload the page after changing the URL, use
the lower-level API, $window.location.href.
https://docs.angularjs.org/guide/$location
I have a link of that kind :
test
On any browser if I want to open this link on a new tab I will get a blank page, which is normal because it's javascript code, note really a link...
But I want the user to be able to open in a new tab, without decrypting the link (SEO matters), is there any way ?
Any constructive comment would be apreciated.
Thx
I think you can not directly decript and open in a new tab, but you could change the order of the two steps in order to open the link in a new tab:
First make a link like this one:
Test
This will open the current page in a new tab, but with an additional parameter in the url.
Now, when the page is loaded in the new tab, you could precheck if ID is set with php or, if it should be a pure js solution, check the parameter like this:
var $_GET = {};
document.location.search.replace(/\??(?:([^=]+)=([^&]*)&?)/g, function () {
function decode(s) { return decodeURIComponent(s.split("+").join(" ")); }
$_GET[decode(arguments[1])] = decode(arguments[2]);
});
custom_url_decrypt_function($_GET["id"]); //Your Own Function which redirects
(You can learn more about getting URL params here)
In this code example you should only replace custom_url_decrypt_function with the name of your decrypt function.
Hope it helped :)
Refining my question little bit this time. :D
I have this function, but instead of opening it in the parent window, I want it to open in a new IE window... and oh "_blank" is not working for me .
function saved() {
str = parent.a.document.abc.text.value;
SER= top.document.open();
SER.write(str);
SER.execCommand();
SER.close();
}
Thanks in advance
-Miss Subanki (LOL I am asking too many questions these days)
This should work:
function saved() {
var str = parent.a.document.abc.text.value;
var win = window.open('','','','height=300,width=400');
var SER= win.document.open();
SER.write(str);
SER.execCommand();
SER.close();
}
We're opening a new window (with win = window.open()), and writing to it. Note that you can pass the normal parameters to it.
Is this what you need:
window.open('http://www.domain.com','','scrollbars=no,menubar=no,height=600,width=800,resizable=yes,toolbar=no,location=no,status=no');
We are use window.open for open popup. But then we want find it and close. Unfortunately we can`t save this popup handle to variable.
P.S. How get list of all windows?
This should work:
var wh = window.open(..)
wh is the handle to the popup window.
If you have control over the page that loads the script, you could do something like this. Warning: this is a really scary and generally bad thing to do:
<script>
var windowHandles = {};
(function() {
var realOpen = window.open;
window.open = function(url, name, features) {
windowHandles[name] = realOpen(url, name, features);
};
})();
</script>
That will build an object (windowHandles) in which the handles for each opened window will be saved.
Put that script in your page before the script that opens the other window is loaded.
I found not perfect solution, but it work.
win = window.open(null, 'Window1');
This code search search window with this name and return handler, but if window is closed it open empty popup.
I Think this is temporary solution
I don't like this solution. Fixing the script to give you a handle would be a better bet.
<button onclick="go()">Go</button>
<button onclick="stop()">Stop</button>
<script type="text/javascript">
function go() {
// Existing function. It opens a window with a name.
window.open('http://google.com', 'test', 'width=300,height=300');
}
var foo;
function stop() {
// Open a new window with the same name. It replaces the existing window.
// Since it opens a local document, the Same Origin Policy does not apply.
// ... and we can capture its return value to grab a handle on an existing
// window
foo = window.open('black-local-page.html', 'test', 'width=300,height=300');
// Give the local page time to load
setTimeout(continue_stopping, 500);
}
function continue_stopping() {
// Call window.open() on the window
foo.close();
}
</script>