link to itunes (itms://...) without opening a new window - javascript

how do i call a link to itunes (itms://...) without opening a new window.
with window.open there comes a new window (as the function says :))
$.get('itms://...'); doesn't work.
Any other possibilitys :)?
would be thankful for help!

Didn't try, but two ideas come to mind:
iframe
set location to the URL, it shouldn't replace your page anyway.

To clarify, you are referring to not opening a new browser window, as opposed to trying to open iTunes within the browser.
In that case, Nickolay's 2nd option is your best bet - this JavaScript will work (using actual example URL):
var url = 'itms://ax.itunes.apple.com/WebObjects/MZStore.woa/wa/viewSoftware?id=307538288';
location.href = url;

Related

Javascript : History back() Method

I was going through the history back() method in Javascript at W3School's website. I was wondering if its possible to go back in history in a new tab.
Lets say I google search "Liverpool fc" and open a website using open link in new tab
Now when the liverpool website opens in a new tab is there a way to go back to the google search?
The below function wont work:
function goBack() {
window.history.back()
}
Is there any way out?
No, it isn't.
That page isn't part of the current window's history.
That is why the browser's back button wouldn't work either.
You can send the url(window.location.href) to the new tab and in the new tab use the history api to push the url to the history state. Look here: Working with the History API
Edit: Misundersood your question.
So, if you want to create this on you own, it is possible to give the url you are opening in the new tab an attribute with the referrer url. Something like this:
http://yourpage.com/?referrer=http%3A%2F%2Fyourpage.com%252Fsublink
Otherwise there is no possiblity for what you want to achieve.
THIS IS NOT THE SOLUTION, JUST DOESN'T WANT TO WASTE IT
It actually is possible. Just take a look at the document object, and you will find a referrer attribute. It's the URL you are coming from.
If you want to open a new tab you should take the workaround from duke that looks like this:
function OpenInNewTab(url) {
var win = window.open(url, '_blank');
win.focus();
}
After this, you can create a new link with an onclick attribute:
<a onclick="OpenInNewTab(document.referrer);">Open last in new tab</a>

Get previous page URL, Open New Window, then Redirect through Javascript

I'm stuck using a CMS that only gives me the ability to modify the content of the <body>, so when I want to redirect people, I've used this
<script type="text/javascript">
window.location = "http://www.example.com/"
</script>
So, yes, the page loads first, and then 5ms later, the redirect happens, and it's worked for all intensive purposes. Now, I'm wondering if I can use javascript to do something else.
Is it possible to open a new browser tab, with a specified URL, and then redirect the user back to the previous page, through Javascript?
Many thanks, SO.
EDIT - Whether it opens a new window or tab, to be honest, is not as important as it actually functioning. I need Javascript to determine the prior page (if possible), then open a new window/tab to a URL I specify, and then redirect the current window/tab to it's prior page. Some are saying that window.open only works on a click event, which will not work for what I am trying accomplish either... just fyi.
So, literally, without clicks, I need Javascript to do the following -
Determine the prior/previous/last page the user came from, store it as a variable
Open a new window or tab, to a specified URL
window.location back to the prior page, which I stored as a variable
Hope that makes sense.
Depending on the user's browser setting using window.open can open the new window in a new tab instead but you CANNOT directly control this through the browser. It is all down to the user's settings.
To open a new window:
window.open("http://www.google.com", "windowName", "window options (optional parameter)");
Then simply use:
history.back();
You can also use the referer property:
var previousUrl = document.referrer;
For more info on window.open, see: http://www.javascript-coder.com/window-popup/javascript-window-open.phtml
For more info on the document.referrer property, take a look at: http://www.netmechanic.com/news/vol4/javascript_no14.htm

Get Previous Page URL via JavaScript after window.open

If I have a script which calls window.open, loading a new page into the same window, then that new page's JavaScript needs to identify the Previous Page's URL - what is the best way to find it?
You can use window.opener.location.href , it will give you the URL of the parent page from which you opened a new window.
You can use window.opener to obtain a reference to the window that opened the current window. Not sure if this is what you are after. When using window.open it will result in a new window, not sure what you mean by "open new window in the same screen".
Using Window.opener you can get it, like
var win=​window.open('http://heera.it')​;
console.log(win.opener.location.href); // will output the url
Example.
​

JavaScript Bookmarklet to open new Window and transmit params of origin Page

I have a perfectly working bookmarklet to grab the Document-Title and the URL of the current Website and place it into the URL of the new loaded Page (Code below) … now I wonder how to let this domain.com/bookmarklet?… open in a new small window (600x600px), so that I still see the old website from where I grabed the title and url in the background and have the new page (domain.com/bookmarklet?…) in the foreground.
javascript:location.href='http://domain.com/bookmarklet?url='+encodeURIComponent(location.href)+';title='+encodeURIComponent(document.title)
How can I achieve that?
Use window.open(...) instead of setting location.href = ....
you need to use window.open() for that
javascript:window.open ("http://domain.com/bookmarklet?.......","MyBookmarklet");

Is it possible to copy, paste, open new window in javascript?

At the moment to get to an external link from our intranet, we have to copy the link, and paste the link into a new window. Is there any way we can achieve this in a single function in javascript?
Thanks
UPDATE:
When users login from outside the network, urls are changed. This is what we need to code for. I think I the following is applied twice, from server side and client side (this code is not editable):
s=s.replace(/location.assign\(([^;]*)\)/g,"location.assign(alter_url($1))")
s=s.replace(/location.replace\(([^;]*)\)/g,"location.replace(alter_url($1))")
if(s.match(/location\s*=\s*([^;]*)(;?)/)!=null&&s.match(/\.open\(.+,.+,.*location\s*=.+\)/)==null)
s=s.replace(/location\s*=\s*([^;]*)(;?)/g,"location=alter_url($1)$2")
s=s.replace(/location\.href\s*=\s*([^;]*)(;?)/g,"location.href=alter_url($1)$2")
s=s.replace(/window\.open\(([^,]*)(,.*)?\)/g,"window.open(alter_url($1)$2)")
s=s.replace(/\.src\s*=\s*([^;]*)(;?)/g,".src=alter_url($1)$2")
s=s.replace(/\.action\s*=\s*([^;]*)(;?)/g,".action=alter_url($1)$2")
s=s.replace(/\.innerHTML\s*=\s*([^;]*)(;?)/g,".innerHTML=alter_html($1)$2")
s=s.replace(/\.outerHTML\s*=\s*([^;]*)(;?)/g,".outerHTML=alter_html($1)$2")
Actually, the more I look at this, the more unrealistic it's becoming..
Right-clicking and choosing "Open in new window" doesn't work? Because if not, I'm not seeing a Javascript workaround working either. But:
You can open a new window with a specific URL (e.g., link) in Javascript easily enough:
window.open("http://stackoverflow.com");
And there are ways of getting the text that's selected in a page, to feed into that. All of which can be wrapped up into a bookmarklet so that the action becomes "select the text, click a link on the bookmark toolbar".
But if "Open in new window" doesn't work, I wouldn't expect that to work either.
You can use the window.open to open the links on a new window. In fact, you could use a bookmarklet to set the target to _blank on every link on the site, in case you can't access the application source code.
BTW, if you hold the Shift key when opening the link it will open on a new window.

Categories

Resources