I have the following code below in a javascript file and need to have the link that is being generated open in a new window.
if (currentSearchType === 'extSearch') {
extSearchSearchValue = extSearchSearchInput.val();
window.location.href = replaceByObject(global.uhg.data['general'].body.extSearchSearchUrl, {
q: extSearchSearchValue
});
Normally with javascript I believe you'd use a window.open type of function, but not sure how to incorporate that with this type of code.
However you do it, opening a new browser window with javascript will most probably be blocked by popup blockers, so perhaps you should rethink your approach to the user himself clicking a regular link, then you can use target="...".
Just use a var to hold the URL and then pass it to window.open()...
if (currentSearchType === 'extSearch') {
extSearchSearchValue = extSearchSearchInput.val();
var url = replaceByObject(global.uhg.data['general'].body.extSearchSearchUrl, {
q: extSearchSearchValue
});
window.open(url, 'searchWindow');
}
Related
I'm a noob. I have a code to simulate a terminal. This is it: https://codepen.io/isdampe/pen/YpgOYr.
Command:
var coreCmds = {
"clear": clear
};
Answer (clear the screen):
function clear(argv, argc) {
termBuffer = "";
return "";
}
As mentioned in the title, how to add a command to launch a new tab in the browser (to google.com for example, or anywhere else)?
Thank you.
window.open();
The open() method opens a new browser window, or a new tab, depending on your browser settings and the parameter values.
Here's an example:
window.open("https://www.google.com");
Structure:
window.open(URL, name, specs, replace)
Since you want to open a new tab in browser, you should put _blank in name. However, this is the default.
What would your code look like?
This is a rough outline, replace variable names and arguments as you like
var var_name = {
"new window": new_window
};
function new_window(arguments) {
termBuffer = "";
return window.open(arguments);
}
I hope this helps :D
Use the window.open method with an input URL.
window.open('https://google.com')
This would open a tab to https://google.com.
When I open the following url in browser,
http://pages.ebay.com/link/?nav=item.view&id=141628727383&alt=web
It redirects to a different url
http://www.ebay.com/itm/141628727383
What's the mechanism?
Because it uses some kind of JS redirection:
var eULin;
window.onload = function() {
eULin = new eUL();
eULin.version = '1.4.1+1424198141014';
eULin.redirect();
}
eUL is defined in http://pages.ebay.com/link/univlink.min.js
eUL.prototype.redirect calls eUL.prototype.winRedirect, which calls location.replace. That replaces the current page with a new one, in a way that the current one won't be accessible using the back button.
How would I go about saving a URL's DOM to a variable without directly opening that page? For example, let's say I have a Chrome extension that allows the user to right click text, search Google, and alert the user with the first result. How would I do this without opening the search results in another tab? Is there any function like saveDOMContent("http://www.google.com/search?q=test") (Note: not a real function) that can do this in pure Javascript?
function getPage(){
var somediv =$('#somediv');
var url='someurl';
var options = {
method:'get',
onSuccess: function(transport){
somediv.innerHTML=transport.responseText;
}
};
new Ajax.Request(url,options);
}
Try something like this, but can not say the same for some cross domain calls
I have to submit a form which opens next page, but URL in next page has to be #/indes/string.
I have a page with input box and button. I already have logic to open new page, transfer parameter via:
var inputStr = document.getElementById('input_box').value;
var w = window.open("indes.html", '_blank');
w.input = inputStr;
and show it on new page with
<script> document.write(input);</script>
But I have to input this "string" to URL so the URL looks like:
#/indes/string
My URL should look like this at the end: www.mydomain.com/#/indes/string
How can I do this? Is this URL-rewriting? Can I even use this on my WAMP?
Check out sammy
Seems just like the thing you are looking for.
I think you need to set the Location Hash Property by setting window.location.hash.
instead of open a new window use location.hash but make sure you prevent default behavior by return false or if you use jquery use preventdefault.
function() {
[your logic]
location.hash = "#/indes/string";
return false
}
I am writing code to download a PDF file using window.open(). I am passing the URL path of the pdf file on a server.
window.open(url, name, "width=910,height=750,scrollbars=yes");
I want to check if the downloading of file is successful or not. What is the return type of window.open()?
I tried like this
try
{
window.open(url, name, "width=910,height=750,scrollbars=yes");
alert("success");
}
catch(e)
{
alert("failer");
}
When I change the URL to a wrong URL, it shows the same result as a success.
http://www.javascripter.net/faq/openinga.htm
The return value is the reference to your new window. You can use
this reference later, for example, to close this window
(winRef.close()), give focus to the window (winRef.focus()) or perform
other window manipulations.
Window.open either returns a handle to the new window opened or null, it will not tell you if the page within the window loaded successfully. If you where opening an html page (from the same domain) you could use this to look into the document
var newWin = window.open();
if(newWin == null) {
alert("darn");
}
newWin.document.getElementById("anElement").innerText = "Fish";