html window open-close by javascript - javascript

I want to close a window open by this javascript written in my landing html page .
window.open(location,"_self");
in the location html page I have a button where I tried with
<div onclick="javascript:self.close();">Xyyyy</div>
<div onclick="javascript:window.close();">Xxxx</div>
None of them work.
Note: my condition in I have to open the new window in the same place.
any help is appriciated

I did a search on the subject and this page is what i found.
html (not mine)
<input type="button" name="Quit" id="Quit" value="Quit" onclick="return quitBox('quit');" />
JavaScript (not mine)
function quitBox(cmd)
{
if (cmd=='quit')
{
open(location, '_self').close();
}
return false;
}
There is even a test page.
I did a search for a bunny rabbit too (which isn't mine either).
Updated : Mar-12-2015
I did a search on the subject and this page is what i found.
I did a test with this code and confirmed it is not supported. The comments are good reading.
JavaScript (not mine)
function close_window() {
if (confirm("Close Window?")) {
window.close();
}
}
html (not mine)
close
close

I don't get completely what you are trying to do but here are some tips:
window.open("https://slackoverflow.com");
is used to open an entirely new window(can be used to open local files as well ofc)
window.close();
window.close() Closes the tab.
<a target="_blank" href="http://your_url_here.html">Page yada yada</a>
And this can be used to open a link or page in a new tab. If you play around with these for a little itll start to catch on.
I hope some of these ideas help and will help you put together what you are trying to accomplish :)

Related

Interactive Popup/White Space

I am fairly new to the world of coding and am currently designing something using WAMP to assist the misses with her maths. In short I have a page with some basic maths questions on and I have JavaScript running on it to check whether the answers are correct or not.
What I would like to know is, can I use JavaScript or something similar to add in a link that if clicked will open a popup or something similar that the user can write a few bits down to help working out the sums?
I have seen a <button onclick="window.open('whitespace.html');">Thinking Space</button> but this doesnt allow the user to write anything down, obviously as its just a link to another page.
A very basic sample, just pointing you in a possible direction:
<button onclick="window.getElementById('myDiv').style.display = 'block'">Thinking Space</button>
<div id="myDiv" style="display: none">
<textarea name="content" cols="40" rows="5">Test message</textarea>
<button onclick="window.getElementById('myDiv').style.display = 'none'">Close</button>
</div>
i think you can use window.promt
https://developer.mozilla.org/de/docs/Web/API/Window/prompt
Maybe not the best answer but works for me. I created a link to a blank page that the user can then open. They can work the questions out, minimise it, forget about it and if they were to try to open a fresh one, close it or try to refresh it, they will get a message asking if they are sure they want to continue. Works exactly as Id hoped.
<textarea placeholder="Please be aware no data will be saved here.
If closed or refreshed all data will be lost"</textarea>
<script>
window.addEventListener("beforeunload", function(event) {
event.returnValue = "Reloading will cause any notes to be lost.";
});
</script>

javascript in iframe won't work

I have a website with lots of code, so obviously something is wrong, but I can't post all the code here. Here's the exact code I'm trying to use though.
Parent document...
<iframe name=combosIframe id=combosIframe src=getCombos.php style='position:absolute;left:300px;top:0px;width:275px;height:520px;overflow-y:scroll;overflow-x:hidden;border:1px solid black'></iframe>
<form name=colorForm id=colorForm action=colorCombos.php method=post target=combosIframe>
<input type=submit id=submitColors value=SubmitColors>
</form>
Inside the iframe, colorCombos.php page...
<script language=JavaScript>
alert('load');
function doSomething(){
alert('hi');
}
</script>
<form>
<input type=button value=ClickMe onClick=doSomething()>
</form>
Scenario: I click the parent form button to load the new page into the iframe.
Problem: the JavaScript in the colorCombos.php page does not alert, either on page load, or when clicking the button. If I view the page on its own it works fine.
Specs: php5, using Chrome browser.
Of note: there are no errors when I view the javascript console. Also there is nothing else on the colorCombos.php page. Both files are in the same directory. Thanks for any help, I'm really stumped.
Not using quotes within HTML Attributes can have undesired effects. Try adding quotes around all the values of each HTML Attribute.
Example:
<input type="button" value="ClickMe" onClick="doSomething()"/>
I started with a blank setup (which was working) copied the code from my site (which has lots of other code), bit by bit into the new document to see when the script stopped working. I ended up copying EVERYTHING (literally ctrl+a) into the new document, and it worked fine. I then renamed the new document to be the name of the old document, and it STOPPED working. The old document (i.e. the parent document) is named rangeTool.php, not that I think that is relevant necessarily.
So I have a solution, but not an answer. What in the world could cause one document to not work? Something wrong on the server? I deleted the old file off the server and loaded the new copy, but that didn't work as long as the name was rangeTool.php. For example, I renamed it testcode.php and it worked fine.
I'm still interested in why/how this happened, but at least the pressure is off now that it's working for me.

Method to open another jsp page in Javascript

I am trying to use buttons in an html/javascript program to redirect someone to another one of my pages. Basically, I created a .jsp page that gives the user some buttons to click. If the user clicks a button, it calls a method that is supposed to open a new .jsp page that I created under the same project. However, I have no clue how to do this as I am brand new to Javascript and HTML. I provided an example below:
Sample Page
<html>
<title>Web Page</title>
<body>
<p>Please click a button to redirect you to the page you wish to go to.</p>
<br>
<form>
<input type="button" id="idname" value = "General Info " onclick="goToInfo()"/><br>
</form>
<br>
<form>
<input type="button" id="idname" value = "Other Information" onclick="goToOther()"/><br>
</form>
<script type="text/javascript">
function goToInfo(){
}
function goToOther(){
}
</script>
</body>
</html>
*For example, I have another page in my NetBeans project that is called "GeneralInfo.jsp" and I want goToInfo() to be able to redirect the person to that page. Thank you for your help.
You could use window.location to redirect the user to the corresponding JSP pages; however, you'll need to make sure your paths in the code below match the actual paths to your JSP page as mapped by your servlet or based on the absolute path relative to the application.
function goToInfo(){
window.location = '/GeneralInfo.jsp';
}
function goToOther(){
window.location = '/someOtherJSPPage.jsp';
}
If you get 404 errors when trying to redirect to your JSP page, try turning up your logging level to ALL or DEBUG so that you can see the logs from the framework or Java container, these will hopefully show you the real file paths so that you can then adjust the URL to match the actual target location.
this should open new tab with GeneralInfo.jsp when you click on the General Info button..
function goToInfo(){
window.location = "GeneralInfo.jsp";
}
you can use this method,
<input type="button" value="General Info" name="INfoPage"
onclick="document.forms[0].action = 'infoPage.jsp';" />
or the easy way is,
General Info

what do i need to open this in a popup or new window?

i'm making a bookmarklet to my website, and for now i have:
<a href="javascript:location.href='http://website.com/compartir_link.php?url='+encodeURIComponent(location.href)" >Save this</a>
wich works fine, the problem is when i try to open it in a new tab: it's like when i try to save: about:blank (in firefox)
And i want to be able to do this without loosing my current video, that's why i thouhgt about a poput, but a funcionally target="_blank" will work for me,
any suggestion?
thank you very mucho!
PD: this link will be saved as a bookmark in my Browser (maybe in my other webistes), Like facebook's bookmarklet/sharer
EDIT
After your replies i have this /js/file.js
jQuery("body").ready(function(){
jQuery(".keep_btn").click(function(event) {
event.preventDefault();
if(this.href=""){
this.href=document.URL;
}
window.open("http://website.com/API/public/compartir_link.php?url="+this.href,'about to keep', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=1,width=450,height=400');
});
});
And i could use it now in a iframe containg:
<a class="keep_btn" href="#" style="background-color:red;color:white;">keeps</a>
Which works for what i need (in case using in an external website)
But how can i use it in a regular so i can save it to my browser?
My best regards
Javascript call...
From Link:
Click Here to Open
From a button in the form:
<input type="button" value="Open the Window" onclick="openIt()" />
function openIt() {
w=window.open(linkUrl, reportName, "resizable=yes, directories=no,location=no,menubar=no,status=no,titlebar=no,toolbar=no,top=50,height=600, width=900");
}
If you're looking for a "pop up", I suggest something like the jQuery UI Dialog.

HTML - overRide statusbar link location display

when on Mouse Over state on a link the status bar shows the link's location in the status bar like in the following image...
is there a way to change\override this to show some desired text...
Most browsers will block attempts to change the status line by default for security reasons (phishing).
You can try it anyway:
link here
A second approach:
link here
Con: you can't open it in a new tabblad / window using Ctrl + click for example.
In ie9 method 1 does not have any effect. Method 2 also defeats the purpose of concealing info, by placing active file path in status bar, rather than customary interpolated uri:
C:\\\filepath\server\local\whatever
Perhaps there is a way to use method 2. Possibly a proxy link-file location intercept. For example:
click here
where c:\links\anylink links to c:\private\privatefile ...?
Further: 'Con: can't open link in new tab / new window' ... javascript?
This should work
<a href="/www.example.com/contact.html" onmouseover="window.status='Contact'" onmouseout="window.status=''">
If you must change the status, here is a cross browser solution that works:
<a href=".: This a link" onClick="window.location='myurl.html';return false">
Downside is that it requires Javascript
Change "This is a link" to required text" and change "myurl.html" to the path of the window file.
If you need to open a url using "_blank" you can create a function that opens a new window instead.
Unfortunately ".:" has to appear at the front of the text otherwise it will render as a url. Tested in IE9. (Firefox and other browsers render this differently
For other browser you could alternatively use "link:" then your url. Tested in Firefox.
NB: you can only change window.status for Opera, (and possible IE 6 and earlier), for security reasons as mentioned in other people's suggestions.
onmouseover or JavaScript are removed from ckeditor of blog sites when we try to input to a page more data next time. So I think, this method should work tested by me in Firefox browser.
<!DOCTYPE html>
<html>
<head>
<style type="text/css">
.btn {
border:none;
}
</style>
<form action="your url">
<input type="submit" class="btn" value="link here">
</form>
</body>
</html>

Categories

Resources