Unable to view the HTML source code of a web page - javascript

Could you please post the HTML source code of this web page:
http://www.xuanyinwen.com/test3.html
I just cannot figure out how to retrieve it..

You can use wget or switch off JavaScript.
P.S.: The magic word is "wen".

Just use "View source" option from tool menu in browser.
<head>
<script language="JavaScript">
var password;
var pass1="wen";
password = prompt('Whats The Magic Word?',' ');
if (password === pass1)
alert('That Is Correct!');
else
window.location="SITE-LINK";
</script>
</head>
<body onLoad="ImageBook()">
TEST
</body>
</html>

"Right-Click + Save Link/Target As..." can be helpful sometimes :) There are several methods of doing this.
<head>
<script language="JavaScript">
var password;
var pass1="wen";
password = prompt('Whats The Magic Word?',' ');
if (password === pass1)
alert('That Is Correct!');
else
window.location="SITE-LINK";
</script>
</head>
<body onLoad="ImageBook()">
TEST
</body>
</html>

Either disable JavaScript on your browser, or use some kind of command line tool (e.g curl).
<head>
<script language="JavaScript">
var password;
var pass1="wen";
password = prompt('Whats The Magic Word?',' ');
if (password === pass1)
alert('That Is Correct!');
else
window.location="SITE-LINK";
</script>
</head>
<body onLoad="ImageBook()">
TEST
</body>
</html>

Use firebug in firefox and select the script.
<head><script language="JavaScript">var password;var pass1="wen";password = prompt('Whats The Magic Word?',' ');if (password === pass1) alert('That Is Correct!');else window.location="SITE-LINK";</script></head> <body onLoad="ImageBook()">TEST </body></html>

Type in keyboard
Ctrl + U in windows 10

Related

include an external JS file into HTML

We have an assignment where I need to insert an external JavaScript file in a html.
HTML File
<!DOCTYPE html>
<title>Color Guessing Game</title>
<body onload="do_game()">
<script type="text/javascript" src="/colguess.js"></script>
</body>
</html>
JS File
var guess_input_color;
var finished=false;
var colors=["blue","cyan","gold","gray","green","magenta","red","white","yellow"];
var guesses=0;
function do_game(){
var n=Math.floor(Math.random()*9);
var color=colors[n];
while(!finished){
guess_input_color=prompt("i am thinking of one of these colors:\n\n"+colors+"\n\nWhat color am i thinking of?");
++guesses;
finished=check_guess();
}
}
function check_guess(){
if(colors.indexOf(guess_input_color)==-1)
{
alert("Sorry, i don't recognize your color.\n\nPlease try again.");
return false;
}
if(color>guess_input_color){
alert("Sorry, your guess is not correct!\n\nHint:your color is alphabetically lesser than mine\n\nPlease try again.");
return false;
}
if(color<guess_input_color){
alert("Sorry, your guess is not correct!\n\nHint:your color is alphabetically higher than mine\n\nPlease try again.");
return false;
}
document.body.style.backgroundColor = guess_input_color;
document.body.style.backgroundColor = guess_input_color;
alert("Congratulations! You have guessed the color!\n\nIt took you"+guesses+" guesses to finish the game!\n\n")
return true;
}
Note: both html and js files are in the same directory.
IT should be this
<script type="text/javascript" src="colguess.js"></script>
not
<script type="text/javascript" src="/colguess.js"></script>
When you reffer '/', it tends to say, looking for the file into the root directory. if files are in the same folder as in html, then no need to use '/'.

How to make the html title change in javascript

I did something like this
<head>
<script src="trans.js" type="text/javascript"></script>
<title><script>trans("Configuration: Status - Software")</script></title>
</head>
However the web title looks like
trans("Configuration: Status - Software")
Why is the js not working here,What should modify to make it work?
Here's what tran.js look like
function trans(key)
{
document.write(getkey(key));
}
function getkey(key)
{
var text;
text = lang_pack[key];
if (text == undefined || text == "")
{
text = key;
}
return(text);
}
I'm not sure you can use a script inside of a title tag -- can you move it into a different block?
It's unclear exactly what trans.js is, but you can try:
<script>
document.title = trans('Configuration: Status -Software');
</script>
You should try setting the title in javascript like
document.title = trans('Configuration: Status - Software');
var temp = document.getElementsByTagName("title").innerHTML;
temp[0].innerHTML = "your new title";
Try including the src in the same script tag as the function call:
<head>
<script src="trans.js" type="text/javascript">trans("Configuration: Status - Software")</script></title>
</head>
Try this:
<head>
<script src="trans.js" type="text/javascript"></script>
<title></title>
<script>document.title = getkey("Configuration: Status - Software")</script>
</head>
You mean this?
<head>
<title>This is Test 1st</title>
<script>
var field = "This is Test 2nd";
$("title").append(field);
</script>
</head>
you need is a jquery library.

HTML/Javascript - username and password

This html code below is suppose to execute and launch an alert asking for a username and if you get the username correct than it will ask for a password but nothing happens if i open this page in a browser. Why this doing this? What am I missing? Please don't tell me this is a unsecure way to do this I already know I'm just improvising until I implant a better way.
<html>
<head>
<script language="JavaScript">
var username;
var user1="grant"
username=prompt('Please Log in. Username:',' ');
if (username=user1);
var pass1="password";
password=prompt('If you are suppose to be here you have a password. Please type it now:',' ');
if (password==pass1);
else {
window.location="wrongpassword.html";
}
else {
window.location="wrongpassword.html";
}
</script>
<body>
</body>
<html>
You are missing some braces. Corrected code (fiddle: http://jsfiddle.net/RyjhP/1/):
var user1="grant";
var username=prompt('Please Log in. Username:',' ');
if (username==user1){
var pass1="password";
password=prompt('If you are suppose to be here you have a password. Please type it now:',' ');
if (password==pass1){
alert("correct!")
}
else {
window.location="wrongpassword.html";
}
}
else {
window.location="wrongpassword.html";
}
short way to do that.
js
window.onload=function(){
window.location=prompt('Enter Pass')!='password'?'wrong.html':'ok.html'
}
example
http://jsfiddle.net/6KzDJ/
but this is a very bad thing.
you should check the password from a secure location with ajax.

How do I set this.location.href to a specific subdomain location

This is a version of Gatekeeper, I'm trying to get this to go to a subdomain of my website but it only goes to specific files on my main domain. Basically I enter 404 and it takes me to: http://mysite.com/404.html and I want it to go to: http://subdomain.mysite.com/404.html I'm kinda new to this but I think I need to change
if (password) { this.location.href = password + ".html"; }
to where the this.location.href doesn't read my current url but the url I specifically want.
Here is the full example code:
<HTML>
<HTML>
<HEAD>
<TITLE>My Page</TITLE>
<SCRIPT language="JavaScript"><!--
/*********************************************************
GateKeeper v2.3 - by Joe Barta
http://www.pagetutor.com/keeper/
Permission is granted to freely use this script.
**********************************************************/
function GateKeeper() {
var password = prompt("Password required:", "");
if (password) { this.location.href = password + ".html"; }}
//--></SCRIPT>
</HEAD>
<BODY>
Click here for my secret page!
</BODY>
</HTML>
Any ideas or suggestions? Thanks in advance!

Why does the browser modify the ID of an HTML element that contains &#x?

Say I've got this HTML page:
<html>
<head>
<script type="text/javascript">
function echoValue(){
var e = document.getElementById("/path/$whatever");
if(e) {
alert(e.innerHTML);
}
else {
alert("not found\n");
}
}
</script>
</head>
<body>
<p id="/path/$whatever">The Value</p>
<button onclick="echoValue()">Tell me</button>
</body>
</html>
I would assume that the browser treats the ID-string /path/$whatever as simple string. Actually, it converts the $ to it's rendered representation ($).
The javascript code however uses the literal string $ to search for the element. So, the call document.getElementById fails and I never get hands on the value of the paragraph.
Is there a way to force the browser into using the given ID string literally?
Edit:
Of course I know that I don't have to escape the $. But the web page gets generated and the generator does the escaping. So, I have to cope with what I've got.
In the <p id="...">, the $ sequence is interpreted as $, because it appears in an attribute and is treated as an HTML entity. Same goes for all other element attributes.
In the <script> element, HTML entities are not interpreted at all, so it shows up literally.
You could try decoding the javascript text without jQuery:
<html>
<head>
<script type="text/javascript">
function decodeEntity(text){
text = text.replace(/<(.*?)>/g,''); // strip out all HTML tags, to prevent possible XSS
var div = document.createElement('div');
div.innerHTML = text;
return div.textContent?div.textContent:div.innerText;
}
function echoValue(){
var e = document.getElementById(decodeEntity("/path/$whatever"));
if(e) {
alert(e.innerHTML);
}
else {
alert("not found\n");
}
}
</script>
</head>
<body>
<p id="/path/$whatever">The Value</p>
<button onclick="echoValue()">Tell me</button>
</body>
</html>
JSFiddle: http://jsfiddle.net/phTkC/
I'd suggest you to decode the HTML entity in your javascript code:
<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<script type="text/javascript">
function echoValue(){
var decoded_string = $('<div />').html("/path/$whatever").text();
var e = document.getElementById(decoded_string);
if(e) {
alert(e.innerHTML);
}
else {
alert("not found\n");
}
}
</script>
</head>
<body>
<p id="/path/$whatever">The Value</p>
<button onclick="echoValue()">Tell me</button>
</body>
</html>

Categories