I am struggeling to implement a function to open a new window with an external link. I am creating dynamic content and would like to write a function that opens up a pop/up window with the given link. Please help. I like jquery dialog boxes, and lightwindo etc. But am unable to implement any of these, any help would be gerat, am stuck and frustrated with this supposingly small issue . . . No option has worked for em so far. here the code of how i display my results, and how i think I have to call the function to open a new window. So the second function here is the one I would need some help with, to open a nice pop-up window displaying the information..
// --------------------- display the course results -> structuring the returned array, to output all information into a table ----------------------
function displayCourses()
{
var str = ' <table border="0" width="530">' +
'<tr>' +
'<td width="150">Title / course code</td>' +
'<td>INFO</td>' +
'</tr>';
if(curCourseList == null)
{
str = str + '<tr><td colspan="2"><div id="msgDips"></div></td></tr>';
}
else
{
for (var i = 0; i < curCourseList.length; i++)
{
str = str + '<tr><td valign="top" width="150"><a style="cursor:pointer;" onclick="showCourse(\''+curCourseList[i][0]+'\')" >' + curCourseList[i][0] + ' <br /> </a>' + curCourseList[i][1] +'<br>'+ curCourseList[i][3] +'<br /><br />'+ curCourseList[i][4] +'</td><td>' + curCourseList[i][2] +'</td></tr>';
}
}
str = str + '</table>';
document.getElementById("courseContainer").innerHTML = str;
if(curCourseList == null)
{
getLangToken('99');
}
}
function showCourse(code)
{
//alert(1)
$.ajax({
async:false,
type: "POST",
url: 'formPostsUser.php?reqtype=getCourse',
data:'coursecode='+ code,
success: function(data)
{
newwindow=window.open(url,'name','height=200,width=150');
if (window.focus) {newwindow.focus()}
return false;
}
});
}
And seriously any help will be greatly ap[preciated. am in such deep shit atm
EDIT---------------
It is the window.open bit i would liek to replace to open a nice fancy pop-up, not new browser window or page
I do not know WHY you say a dialog does not work or specifically if jQuery UI dialog does not work for you, but just in case:
$(function() {
$("<div id='helpDialog' style='display:none' />").appendTo(document);
$("#helpDialog").dialog({
autoOpen: false
});
$("#helpDialog").dialog('option', 'buttons', {
"Close": function() {
$(this).dialog("close");
}
})
});
function helpPopUp(page, height, width) {
$("#helpDialog").dialog('option', 'height', height);
$("#helpDialog").dialog('option', 'width', width);
$('#helpDialog').load(page);
$('#helpDialog').dialog("open");
}
helpPopUp('#helpDialog', 'Help/Summary.html', 550, 750);
You could of course, modify the .load(page) to be custom IF needed referencing the page in your url.
Here is a simple sample of the above with a slight mod to load your table instead of the page: http://jsfiddle.net/MarkSchultheiss/ABqrD/1/
If your triggering the window opening via anything other than user interaction it will most likely be blocked. Have you checked for notices pertaining to this?
If you don't want to use a real popup, you could try to create a <div> which 'hovers' above the page with something like
.hoverwindow {
position:absolute;
width: ...px;
height:...px;
margin:auto;
z-index:10; /*ensure that it's displayed on top*/
}
You could do this with a small modification of your function:
function showCourse(code)
{
$.ajax({
async:false,
type: "POST",
url: 'formPostsUser.php?reqtype=getCourse',
data:'coursecode='+ code,
success: function(data)
{
var newwindow = $('<div class="hoverwindow" />');
newwindow.html(data).appendTo('body');
}
});
}
Although frankly this is pretty much what plugins for "popups" do so all of this should be readily available online if you search for it. Hence why I have not bothered to actually try and test this code - it is simply to give an idea of what you could do.
Related
I want to scrape some data from webpage that is Cross Reference and Model Information
I have a script which scraped all other data form page.
But as required data is coming from Ajax call in Div by id.
<div class="inner" style="overflow-x: hidden; overflow-y: scroll; height:300px;" id="xmodellist"><table>
<tbody><tr>
<th>Manufacturer</th>
<th>Model Number</th>
<th>Description</th>
</tr>
<tr>
<td>Amana</td>
<td>SXD26VW</td>
<td>REF - SXS/I&W</td>
</tr></tbody></table>
</div>
Ajax Code of webpage from view source
$.ajax({
url: "/partmodellist.aspx?partid=" + partid + "&os=" + os.toString(),
success: function (data) {
if (data) {
$('#xmodel1').replaceWith(data);
$('#xmodellist').scroll(function () {
if (($('tr#trxrefloading').length > 0) && $('#xmodellist').scrollTop() + $('#xmodellist').innerHeight() >= $('#xmodellist')[0].scrollHeight) {
os = os + 1;
$.ajax({
url: "/partmodellist.aspx?partid=" + partid + "&os=" + os.toString(),
success: function (html) {
if (html) {
if (html.trim().length > 0)
{
$("tr#trxrefloading").before(html);
}
else
{
$('tr#trxrefloading').css("display", "none");
$('#xmodellist').unbind();
}
} else {
$('tr#trxrefloading').css("display", "none");
$('#xmodellist').unbind();
}
}
});
}
});
} else {
$('xmodel1').css("display", "none");
}
}
});
I want to scrape all information in that div.
I have attached my existing code file. or this link
Please provide suggestion that how can I achieve this.
You can directly use CURL to simulation request to get data from partmodellist.aspx rather than scrape it or simulate browser behavior by selenium lib.
What is Selenium?
I was also trying to scrape ajax in php and found this:
http://256cats.com/scraping-asp-websites-php-dopostback-ajax-emulation/
I tried to implement it but I'm not a developer so my skills are limited and I am actually trying to do something much simpler than the example shown in the article. By that I mean: I couldn't do it. I also tried contacting the developer with no success.
But it might interest you.
I have a simple installer that's divided in segments, not by syntax, but just by logic. Here's how it works:
if ($_POST['install'] == "Install")
{
// fetches user values
// creates tables
// creates some files
// creates some emails
// inserts relevant stuff into the database
// finishes
}
The code is too long and unnecessary for this question. Each of those steps counts as 20% complete for the installation, how would I make a progress bar displaying the info to the user? I'd like this for two reasons, one is for them to keep track, other is for them to know they shouldn't close the browser tab before it's done.
Now my idea is to assign a variable to each part of the code, for instance $done = 20% in the first, $done = 40% in the second etc, and simply show progress bar based on that variable. The the only thing I don't know is how to show the progress bar?
Thanks
My recommended solution:
Create separate ajax requests for each step in your process like so...
// do first step
$.ajax({
url: myUrl + '?step=1',
success: function() {
// update progress bar 20%
}
});
// do second step
$.ajax({
url: myUrl + '?step=2',
success: function() {
// update progress bar 40%
}
});
// etc.
If you want to be DRY, try this:
var steps = 5;
for (var i = 1; i <= steps; i++) {
$.ajax({
url: myUrl + '?step=' + i;
success: function() {
// update success incrementally
}
});
}
With jQuery UI progressbar:
$(function() {
$("#progressbar").progressbar({
value: 0
});
var steps = 5;
for (var i = 1; i <= steps; i++) {
$.ajax({
url: myUrl + '?step=' + i;
success: function() {
// update success incrementally
$("#progressbar").progressbar('value', i * 20);
}
});
}
});
Ref. http://jqueryui.com/progressbar/#default
The best practice is to store the progress value in a db or a key-value storage system such as APC, Memcache or Redis. And then retrieve the progress with an ajax query.
A good jquery plugin is progressbar bar from jQuery-ui, and you can use json to encode the progress value:
// GET /ajax/get-status.json
{
"progress":10,
"error":"",
"warning":""
}
The page:
<div id="error" style="color: red"></div>
<div id="warning" style="color: yellow"></div>
<div id="message"></div>
<div id="progressbar"></div>
<script type="text/javascript">
jQuery(document).ready(function() {
$("#progressbar").progressbar({ value: 0 });
$.ajaxSetup({ cache: false });
function updateProgress() {
jQuery.getJSON("/ajax/get-status.json", function(response) {
if (response.error) {
$("#error").html( response.error );
return;
} else {
$("#progressbar").progressbar( 'value', parseInt( response.progress ) ); // Add the new value to the progress bar
$("#message").html( response.message );
$("#warning").html( response.warning );
if(parseInt( response.progress ) < 100){
setTimeout(updateProgress, 1);
}
}
});
}
updateProgress();
});
</script>
You can use an HTML5 progress bar.
Send ajax request and return the percent complete.
Change the progress tag's value.
<progress id='p' max="100" value="50"></progress>
I'm quite new with jquery but I wanted to add a quick preview of notes for users after they move mouse on the title of the note. But also, after they click on it I wanted them to edit the note. So I have two separate actions (in php )- for clicking and editing I have getNote and for quick preview I have fastNote. They work just fine, problem is with the jquery code - everything is great but after I click on link to edit the note and I went back the preview is not working anymore. Here is the jquery code:
$(document).ready(function() {
$(".note").mousemove(function (e) {
link = $(this).attr('href');
link = link.replace("getNote","fastNote");
$(this).attr('href',link);
$.ajax( {
type: "GET",
url: link,
success: function(result) {
$("#news2").html( result ) ;
put_preview(e) ;
}
});
});
$(".note").click( function() {
link = link.replace("fastNote","getNote");
$(this).attr('href',link);
});
$(".note").mouseout( function() {
$("#news2").css('display','none');
}) ;
function put_preview(e) {
$("#news2").html("<b>Notatka: </b><br />" + $("#news2").html());
$("#news2").css('background-color','yellow');
$("#news2").css('padding-top','5px');
$("#news2").css('text-align','center');
$("#news2").css('border','4px dotted blue');
$("#news2").css('width','400px');
$('#news2').css('position','absolute');
$('#news2').css({'top': e.pageY - 20, left: e.pageX + 20});
$("#news2").show();
}
});
and I don't have any idea why it stops working once it's clicked.
I'm looking to put a div on my website where the content changes based on what link is clicked without refreshing. The content to put there comes from a MySQL database and it's put in JSON.
My problem is that I can't get the JSON data to display when clicking the links.
Here's the script I'm using:
$(document).ready(function () {
$.getJSON("jsondata.php",rightSideData);
function rightSideData(data) {
for(var i=0; i<data.length;i++) {
$("#changetext"+data[i].id).click(function() {
$("#rightside").html("<h1>" + data[i].title + "</h1><p />" + data[i].content);
});
}
}
});
This is the div element that has to change:
<div class='rightside' id='rightside'>Test</div>
The links are constructed this way:
echo "<a id='changetext" . $row['id'] . "'> ";
echo "<div class='tile'>";
echo "<h2>Tile</h2></div></a>";
I've tested the different elements and they work fine (changing the divs content with hardcoded data, displaying the JSON data), but I'm having a hard time figuring out why the combined thing isn't working.
Objects does'nt have a length, use $.each to iterate it instead, unless it's actually an array containing objects :
$(document).ready(function () {
$.getJSON("jsondata.php",rightSideData);
function rightSideData(data) {
$.each(data, function(i, d) {
$("#changetext" + d.id).on('click', function() {
var h1 = $('<h1 />', {text : d.title}),
p = $('<p />', {text : d.content});
$("#rightside").html(h1.add(p));
});
});
}
});
The problem is that i var will be data.length at the end of the loop and that's what the click handler will see.
Hey all, I am facing a rather serious security error. Let me first outline my code.
<li class="comment">
<form action="" method="POST" name="edit-form" class="edit-area">
<textarea style="width: 100%; height: 150px;"><?php echo $response->comment; ?></textarea>
</form>
<div class="comment-area" style="padding-top: 2px"><?php echo (parseResponse($response->comment)); ?></div>
<p class="ranking">
<?php if ($response->user_id == $user_id) : ?>
Edit • Delete
<?php else : ?>
Like (<?php echo $response->likes; ?>) • Dislike (<?php echo $response->dislikes; ?>)
<?php endif; ?>
</p>
</li>
is what I got in my body, and here's the relevant JS
$('.editting').bind('click', function(event) {
var num = $(this).data('edit');
var user = $(this).data('user');
if ($(this).hasClass('done')) {
var newComment = $('#comment-' + num + ' .edit-area textarea').val();
var dataString = 'newComment='+ newComment + '&num=' + num;
if(newComment == '')
{
alert('Comment Cannot Be Empty!');
}
else
{
$.ajax({
type: "POST",
url: "edit.php",
data: dataString,
success: function(){}
});
$('#comment-' + num + ' .edit-area').slideDown('slow', function() {
$('#comment-' + num + ' .edit-area').addClass('invisible');
});
$('#comment-' + num + ' .comment-area').slideUp('slow', function() {
$('#comment-' + num + ' .comment-area').removeClass('invisible');
});
$(this).removeClass('done');
$(this).html('Edit');
}
}
else {
$('#comment-' + num + ' .comment-area').slideDown('slow', function() {
$('#comment-' + num + ' .comment-area').addClass('invisible');
});
$('#comment-' + num + ' .edit-area').slideUp('slow', function() {
$('#comment-' + num + ' .edit-area').removeClass('invisible');
});
$(this).html('Done');
$(this).addClass('done');
}
return false;
});
which works fine, but i'm having an issue. If the user finds a comment (not by them) and uses a plugin like firebug, they can replace the response->short with another, and edit ANY comment. Of course, within edit.php, I could check the short against the response table and see if the user checks out, but i'd like to find a way to not show the text area unless that response is for-sure by that user.
Is this possible?
Thanks in advance,
Will
Is this possible?
Sure...but it'll do nothing to stop the user/fix your security hole. To fix this check server-side, always double-check anything that should be secure server-side, never trust your input. The users trying to do something malicious won't be stopped by anything in JavaScript...sending data to your server that they shouldn't is exactly what they'll do first.
Like Nick said; never ever trust a JavaScript test!
It will/might work for "regular users", but when it comes down to avoiding hacks, you might as well ask the hacker to click a button to "prove" his input is valid!
Your validator script is running on someone else's computer, so he/she will be able to manipulate it (or even turn it of using NoScript etc. )