I'm a relatively light JavaScript user, so this minor operation is giving me some major grief -- I'm sure I'm missing something.
All I want is a popup to open, passing one value -- the emplogin, a string variable called getEmp -- to a bog-standard .php page thusly:
<script type="text/javascript">
function getEmployeeInfo(getEmp)
{
window.open ("../Pages/Employee_Info.php?emplogin=" + getEmp + ",\"mywin\",\"menubar=0,resizable=1,scrollbars=1,width=600,height=450\"");
}
</script>
And it works... sort of. Testing the result by looking at the resulting $_REQUEST object shows me that the page is receiving the $emplogin as
Array
(
[emplogin] =>JohnDoe,"mywin","menubar=0,resizable=1,scrollbars=1,width=600,height=450"
)
IOW, the second and third parameters for Window.Open() are being passed along as part of the $emplogin received by PHP, instead of being parsed by JavaScript! (I'm using 'echo htmlspecialchars(print_r($_REQUEST, true));')
I'm sure there's something I'm not doing right with the escaping of the parameters but I haven't been able to hit on the right search terms. Thank you for any and all guidance!
Try this:
<script type="text/javascript">
function getEmployeeInfo(getEmp)
{
window.open ("../Pages/Employee_Info.php?emplogin=" + getEmp, "mywin", "menubar=0,resizable=1,scrollbars=1,width=600,height=450");
}
</script>
You're including your second and third parameters as part of your URL string, so it's all being treated as one single parameter.
What you want is:
window.open ("../Pages/Employee_Info.php?emplogin=" + getEmp,"mywin","menubar=0,resizable=1,scrollbars=1,width=600,height=450");
That is how it should be:
<script type="text/javascript">
function getEmployeeInfo(getEmp)
{
window.open ("../Pages/Employee_Info.php?emplogin=" + getEmp + ,"mywin","menubar=0,resizable=1,scrollbars=1,width=600,height=450");
}
</script>
urlencode your variable and remove the escaping of your other parameters in the open command
Related
This question already has answers here:
What is the difference between client-side and server-side programming?
(3 answers)
Closed 6 years ago.
I'm not sure if this is even possible, but here goes.
I have a PHP function called code_check_result($code_name). It checks in the database and returns a bunch of information regarding the supplied code's name.
The name of the code is found within a span tag in the page. I've made a javascript function that opens a new window which should then execute the PHP function. However, the variable needed in the PHP function is stored in a jquery var as I have selected the span tag and stored whatever's inside.
Below you can see the part of the code where the window is created (just the part with the PHP function).
myWindow.document.write('Tjek: ' + code_name + '</br></br></br></br><?php code_check_result("kode2"); ?>');
"kode2" is the actual name of a code. The above works exactly as it's supposed to. However, if I substitute the "kode2" string with the javascript variable, 'code_name', it doesn't work. Like this:
myWindow.document.write('Tjek: ' + code_name + '</br></br></br></br><?php code_check_result("' + code_name + '"); ?>');
The first occurence of code_name writes it to the page, but the second one within the PHP function doesn't work.
I'm pretty sure this is just because the PHP is executed before the 'code_name' variable is written as a string. But I'm not entirely sure.
So, I'd appreciate it if you could either help me figuring out how to do this, OR tell me to abandon this idea because it's not possible and then give me some pointers as to how else to solve this.
Given this:
the variable needed in the PHP function is stored in a jquery var
and this:
I've made a javascript function that opens a new window
It sounds like you just need to pass a value to the URL being opened in that window. So where you might have something like this:
window.open('somePage.php');
You would instead have this:
window.open('somePage.php?someValue=' + myVariable);
The URL of the window being opened is a normal URL like any other. You can include values on the query string, and the PHP code in somePage.php can read them from the$_GET collection.
It will be easier to create $_POST variable with jQuery. Something like this:
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
<script>
$.ajax({
type: "POST",
url: "[URL GOES HERE]",
data:{ VARNAME: VALUE },
success: function(data){
console.log(data);
}
})
</script>
Been looking around for an answer to this. Thought I had found a solution but it didn't work. Here's what I tried.
Created a javascript function as follows:
function openInNewWindow( url ){
window.open( url, '_blank', 'height=200' );}
Created a hotspot with the following in the computed value:
#URLOpen("javascript:openInNewWndow('http://www.google.com')")
This just replaces the current tab but does not open a new browser window. Is there another way to do this?
thanks
clem
You should specify fullscreen option.
window.open("http://example.com","_blank","fullscreen=0");
But your program can't do anything with popup blockers.
#URLOpen("javascript:openInNewWndow('http://www.google.com')")
Is that your actual code pasted in? because you missed the 'i' in openInNewWindow
Also, I'm not sure you can specify a height without specifying a width.
You might also investigate how #urlopen works, there shouldn't be any need to mix in javascript at all.
When a Notes browser triggers the #URLOpen function, it displays the retrieved Web page in a new window. When the #URLOpen function is used on a form or page that is accessed by a non-Notes browser, Domino generates a javascript window.open command with the following syntax:
window.open( [sURL] [, sName] [, sFeatures] [, bReplace])
To display the retrieved Web page in a new window, pass the values for sName and sFeatures (if desired) as comma-separated arguments within the urlstring. For example,
#URLOpen("http://www.ibm.com','NEW")
Be sure to use double quotes at the beginning and end of the urlstring parameter, and single quotes before and after each comma separating the arguments to be passed to window.open. Do not include any spaces.
IBM Knowledge Center
The #openurl just didn't work. I finally got it to work using this on the form:
[Test]
Thanks for the replies. Appreciate the input.
clem
I want to pass url parameter through html dom. This is the javascript i am using
<script>
function myFunction(url)
{
setTimeout(function(){window.location.assign(url)},4000);
}
</script>
HTML
Click here
But its not working. How can i fix this situation ? Thanks for your answers.
Use combination of single and double quotes, to pass the url as string literal. If the url is not enclosed in quotes it is considered as some variable and javascript could nod find that.
Click here
As #Adil says, you need to pass the argument as string to the function. In the way you are trying, the script is trying to recover the value of the http://stackoverflow.com variable.
what #Adil has said is true:
Click here
but if you want to pass the url as a parameter do not forget to change your function like this:
function myFunction(url)
{
setTimeout(function(){window.location.assign(encodeURIComponent(url)},4000);
}
I am using the following code in javascript's document.write method :
<script type="text/javascript">
document.write("<font color="blue">["+time()+"]</font>");
</script>
But this doesn't seem to work.
Please guide me.
The problem has nothing to do with HTML directly, simply with how string literals work in JavaScript (and pretty much every other programming language). If you want to use a " character inside a JavaScript string that is delimited with " characters then you must escape it: \". Alternatively use ' to delimit either the string or the attribute values.
document.write("<font color=\"blue\">["+time()+"]</font>");
document.write('<font color="blue">['+time()+"]</font>");
document.write("<font color='blue'>["+time()+"]</font>");
That said, generating HTML using document.write usually isn't a great idea (it only works at load time, is usually better replaced with more reliable server side code or more reusable DOM manipulation)) and the font element is deprecated.
<script type="text/javascript">
document.write("<font color=\"blue\">[" + time() + "]</font>");
</script>
or
<script type="text/javascript">
document.write('<font color="blue">[' + time() + ']</font>');
</script>
Note that time doesn't exist as a function in JavaScript—I'm assuming you made a function above that wasn't included in your code snippet. Also you shouldn't really use document.write for anything unless you're just experimenting. You could test all this out using console.log in Firefox's Firebug or Safari / Chrome Web Inspector, would be way faster for experimenting than full page refreshes. Also noticed how I added spaces on either side of the + sign: way easier to read.
you can use css instead of html and its pretty simple
window.document.write("<span style=\"color:blue;font-size: 5em;\">hello " + variable + "<\/span>");
var color = 'blue';
document.write("<font color="+color+">["+time()+"]</font>");
Or
document.write("<font color='blue'>["+time()+"]</font>");
This is my code all I need to do is call a function which will write the contents to a dynamic div
<script language='javascript' type='text/javascript'>
function getComments(id)
{
alert(id);
}
var resultSet="";
function CreateDiv()
{
resultSet+="<br/><div id='"+rows.data[i].id+"'></div><script language='javascript' type='text/javascript'> getComments("+rows.data[i].id+"); <\/script>";
}
window.onload=CreateDiv;
</script>
The function getComments is not being called at all
What's that I am missing here
There are a few problems there.
You're referencing rows without defining it anywhere, which will cause an exception.
Assuming you define rows somewhere you haven't shown, the code's just creating a string containing a script tag and putting that string in resultSet. To cause the code inside the script tag to run, you'd have to assign resultSet to innerHTML on some element.
There's an extra ) in your call to getComments within the generated script.
Separately: Your id values would appear to be numbers (this is based on your passing them into getComments with no quotes around them). Note that using id values starting with a digit is allowed in HTML5, but not in earlier versions of HTML and not in CSS, so it's probably best avoided.
There's almost certainly a better way to do what you're actually trying to do, you may consider a separate question outlining the goal, how you've approached it so far, and asking for alternatives.
I would suggest that you break the code down into steps while you debug it. Specifically where you populate resultSet. Break it down at each plus sign. Then you can step through it and see how it is being populated.
resultSet+="<br/><div id='";
resultSet+=rows.data[i].id;
and so on.
Secondly, have a look in View Source to see what this looks like on the page when you run it. Does the HTML look properly formed?
Also, I am questioning whether that final <\/script> in resultSet is correct.
Try replacing the createDiv function with this:
function CreateDiv(){
resultSet += "<br/><div id='"+rows.data[i].id+"'></div>" + getComments(rows.data[i].id);
}
It should work flawlessly.